package com.web.webrecive.utils;

import org.apache.commons.codec.digest.DigestUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Base64;
import java.util.Date;

/**
 * Created by admin on 2017/7/19.
 */
public class FileUtil {
    //获取信息摘要，唯一值
    public static String getSha512HexStr(String str) {
        String sha512str= null;
        try {
            sha512str = DigestUtils.sha512Hex(new FileInputStream(str));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return sha512str;
    }
    //byte数组转换成字符串，使用base64
    public static String getString(byte [] bytes){
        return  Base64.getEncoder().encodeToString(bytes);
    }

    public static String getFileInfo(String filePath){
        File file = new File(filePath); //创建文件对象
        return file.getName()+"&&"+file.getPath()+"&&"+file.getAbsolutePath()+"&&"+file.length()+ "B"+"&&"+new Date(file.lastModified())
                +"&&"+file.isFile()+"&&"+getSha512HexStr(filePath) ;
    }
}
